import time
import subprocess
from xiaopy import *
from cotc import COTC

subprocess.run(["su", "root"])

try:
    ui = xp.ui()
    region = "tw"
    c = COTC(region)
except Exception as e:
    xp.toast(e)


def run_script():
    time.sleep(0.5)
    print("点击果炎采集点……")
    xp.tap(371, 417)

    time.sleep(1)
    print("检查获取物品……")
    if not c.wait_item_obtain():
        print("点击对象有误，脚本结束。")
        return

    time.sleep(0.2)
    success = False

    if xp.findColor("#FFFFFF", "1|1|#FFFFFF", 541, 339, 543, 341):
        print("--获取100果炎果实--")
        success = True

    if success:
        return
    else:
        print("--获取失败--")
        c.restart_cotc()
    run_script()


run_script()
